<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>研学旅行</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/css/font.css}">
	<link rel="stylesheet" th:href="@{/css/xadmin.css}">
	
<!-- 	<link rel="stylesheet" th:href="@{/layui-v2.4.5/layui/css/layui.css}"> -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/Swiper/3.4.2/css/swiper.min.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
   
   <script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
   <script th:src="@{/lib/layui/layui.js}" charset="UTF-8"></script>
     
     
   
    <script th:src="@{/js/xadmin.js}"></script>
</head>

	<script>
		
		  
		 
		  
		  $(function(){
		    
		    
		  
		 
		  	
		  	
		  	var s=0;
		  	$("#yc").click(function(){
		  		if(s==0){
		  			$("#jl").show();
		  			$("#tb").html("&#xe6a6;")
		  			s=1;
		  		}else{
		  			$("#jl").hide();
		  			$("#tb").html("&#xe6a7;")
		  			s=0;
		  			
		  		}
		  		
		  	})
		  	
		  	var h=0;
		  	$("[name='xxjl']").click(function(){
		  		if(h==0){
		  			$(this).next().show();
		  			$(this).find("i").html("&#xe6a6;")
		  			h=1;
		  		}else{
		  			$(this).next().hide();
		  			$(this).find("i").html("&#xe6a7;")
		  			h=0;
		  			
		  		}
		  		
		  	})
		  	
		  	
		  	var x=0;
		  		$("#yc1").click(function(){
		  		if(x==0){
		  			$("#cd").show();
		  			$("#tb1").html("&#xe6a6;")
		  			x=1;
		  		}else{
		  			$("#cd").hide();
		  			$("#tb1").html("&#xe6a7;")
		  			x=0;
		  			
		  		}
		  		
		  	})
		  		
		  		
		  		 	var z=0;
		  	$("[name='xxcd']").click(function(){
		  		if(z==0){
		  			$(this).next().show();
		  			$(this).find("i").html("&#xe6a6;")
		  			z=1;
		  		}else{
		  			$(this).next().hide();
		  			$(this).find("i").html("&#xe6a7;")
		  			z=0;
		  			
		  		}
		  		
		  	})
		  	
		  })
		  
	
	</script>
	
	
	
<body>
    <!-- 中部开始 -->
    
    
    
    
    
    <div class="wrapper">
        <!-- 右侧主体开始 -->
        <div class="page-content">
          <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            
              
            
            <form class="layui-form" enctype="multipart/form-data">
              
             
              
              
                <div class="layui-form-item">
                    <label for="L_username" class="layui-form-label">
                        <span class="x-red">*</span>项目名称
                    </label>
                    <div class="layui-input-inline">
                     <input type="hidden" id="L_username" name="pid"  lay-verify="nikename"
                        autocomplete="off" class="layui-input">
                        <input type="text" id="L_username" name="projectname"  lay-verify="nikename"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
                
                <div class="layui-form-item layui-form-text">
                    <label for="L_sign" class="layui-form-label">
                        <span class="x-red">*</span>项目介绍
                    </label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入项目介绍" id="L_sign" name="context" autocomplete="off"
                        class="layui-textarea" style="height: 80px;"></textarea>
                    </div>
                </div>
                
                <div class="layui-form-item layui-form-text">
                    <label for="L_sign" class="layui-form-label">
                        <span class="x-red">*</span>价格（/人）
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_username" name="price"  lay-verify="nikename"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
                
                <div class="layui-form-item layui-form-text">
                    <label for="L_sign" class="layui-form-label">
                        <span class="x-red">*</span>图片选择
                    </label>
                    <div class="layui-input-block">
                       <input type="file" id="exampleInputFile" multiple="multiple" name="file">
                    </div>
                </div>
                
                
                
               
                 
                 
                
              
                
                   <div class="layui-form-item">
                    <label for="L_username" class="layui-form-label">
                        <span class="x-red">*</span>请选择类型
                    </label>
                    <div class="layui-inline">
            
                    <select lay-filter="test" name="type">
                        <option>请选择</option>
                    	<option th:each="l,state : ${list}" th:text="${l.name}" th:value="${l.id}"></option>
                    	
                    </select>
          
           
            
                    </div>   
             
                </div>
                
                 
                <div id="yc"><xblock><i class="iconfont nav_right" id="tb">&#xe6a7;</i>请选择教练</xblock></div>
                
                <div id="jl" style="display: none">
                
            
                </div>
                 
                  
                  
                    <div id="yc1"><xblock><i class="iconfont nav_right" id="tb1">&#xe6a7;</i>请选择场地</xblock></div>
                
                  
                 <div id="cd" style="display: none">
                  		
                  			
                  		
                  	</div>
                  
                  	
                  
                  
          
                
               
                
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" th:onclick="zj()">
                        增加
                    </button>
                </div>
            </form>
            <!-- 右侧内容框架，更改从这里结束 -->
          </div>
        </div>
        <!-- 右侧主体结束 -->
    </div>
    <!-- 中部结束 -->
    
    
    
  
</body>
 <script th:src="@{/layui-v2.4.5/layui/layui.js}"></script>
<script type="text/javascript" th:inline="javascript">
    var urlpath = [[@{/project/queryjl}]];
    
    var urlpath1=[[@{/project/querycd}]];
    
    var urlpath2=[[@{/project/fileupload}]];
    
    var urlpath3=[[@{/project/projectadd}]];
    
  

$(function(){
	
	 layui.use('form', function(){
		  var form = layui.form;
		 form.on('select(test)', function(data){
			 
			
		  //得到select原始DOM对象
		  //得到被选中的值
		 	$.ajax({
			 url:urlpath,
			 data:{
				 fid:data.value
			 },
			 async: false,
			 datatype:"json",
			 
			 success:function(res){
				 console.log(res);
				 if(res!=null){
					 $("#jl").html("");
					for(var i=0;i<res.length;i++){
 						 $("#jl").append("<input type='checkbox' value='"+res[i].id+"' name='eid'>"+res[i].employeename);
					
					}
					
					
					 form.render();
				 }
             
				
			 }
				})
				
				

				$.ajax({
			 url:urlpath1,
			 data:{
				 tid:data.value
			 },
			 async: false,
			 datatype:"json",
			 
			 success:function(res){
				 console.log(res);
				 if(res!=null){
					 $("#cd").html("");
					for(var i=0;i<res.length;i++){
 						 $("#cd").append("<input type='checkbox' value='"+res[i].id+"' name='cid'>"+res[i].name);
					
					}
					
					
					 form.render();
				 }
             
				
			 }
				})
				
				
 
				});  
			});
	 
// 	 $("[name='zj']").click(function(){
		 
// 		 var modules=[];
// 		  $("[name='eid']").each(function() {
// 			if(this.checked){
// 				var model={};
// 				model.id=$(this).val();
				
				
// 				modules.push(model);
// 			}
				
		
// 		})
		
// 		 var modules1=[];
// 		  $("[name='cid']").each(function() {
// 			if(this.checked){
// 				var model={};
// 				model.id=$(this).val();
				
				
// 				modules1.push(model);
// 			}
				
		
// 		})
		
// 		var project={};
		  
// 		  project.projectname=$("[name='projectname']").val();
// 		  project.price=$("[name='price']").val();
// 		  project.context=$("[name='context']").val();
// 		  project.type=$("[name='type']").val();
// 		  project.emlist=modules;
// 		  project.flist= modules1;
		  
// 		  var  projectStr=JSON.stringify( project);
// 		  console.log(projectStr);
		  
// 		  $.ajax({
// 			  url:urlpath3,
// 			  data:projectStr,
// 			  type:"post",
// 			  async : false,
// 			  processData:false,
// 			  contentType:"application/json",
// 			  datatype:"text",
// 			  success:function(data){
				  
				
// 			    imgadd(data);
// 			  }
// 		  })
		  
		  
	     
		 
		 
// 	 })
	 
	 
	 
})

   function zj(){
	 var modules=[];
	  $("[name='eid']").each(function() {
		if(this.checked){
			var model={};
			model.id=$(this).val();
			
			
			modules.push(model);
		}
			
	
	})
	
	 var modules1=[];
	  $("[name='cid']").each(function() {
		if(this.checked){
			var model={};
			model.id=$(this).val();
			
			
			modules1.push(model);
		}
			
	
	})
	
	var project={};
	  
	  project.projectname=$("[name='projectname']").val();
	  project.price=$("[name='price']").val();
	  project.context=$("[name='context']").val();
	  project.type=$("[name='type']").val();
	  project.emlist=modules;
	  project.flist= modules1;
	  
	  var  projectStr=JSON.stringify( project);
	  console.log(projectStr);
	  
	  $.ajax({
		  url:urlpath3,
		  data:projectStr,
		  type:"post",
		  async : false,
		  processData:false,
		  contentType:"application/json",
		  datatype:"text",
		  success:function(data){
			  
			
		    imgadd(data);
		  }
	  })
	  
	 var index=parent.layer.getFrameIndex(window.name);
	  parent.layer.close(index);
}


  function imgadd(data){
	$("[name='pid']").val(data);
  	  var form=$("form")[0];
	  var formdata=new FormData(form);
	  console.log(formdata);
	  
	  $.ajax({
		  url:urlpath2,
		  data:formdata,
		  type:"post",
		  async : false,
		  contentType:false,
		  processData:false,
		  sucess:function(result){
			 alert("新增成功");
			  console.log(result);
			  
		  }
		  
		  
	  })
    }

</script>


</html>